package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.Taxonomy;
import com.fsnbigdata.domain.Organism;
import com.fsnbigdata.domain.QTaxonomy;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = TaxonomyRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = TaxonomyRepositoryCustom.class)
@Transactional(readOnly = true)
public class TaxonomyRepositoryImpl extends QueryDslRepositorySupportExt<Taxonomy> implements TaxonomyRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    TaxonomyRepositoryImpl() {
        super(Taxonomy.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FAMILY_LATIN = "familyLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_CLASS = "subClass";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String GENUS = "genus";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SPECIES = "species";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_CLASS_LATIN = "subClassLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PHYLUMN_LATIN = "phylumnLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_PHYLUMN_LATIN = "subPhylumnLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ORGANISM = "organism";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String FAMILY = "family";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String T_CLASS_LATIN = "tClassLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PHYLUMN = "phylumn";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_FAMILY = "subFamily";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String GENUS_LATIN = "genusLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String T_CLASS = "tClass";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String KINGDOM = "kingdom";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_GENUS = "subGenus";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SPECIES_LATIN = "speciesLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_KINGDOM = "subKingdom";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_SPECIES_LATIN = "subSpeciesLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String T_ORDER_LATIN = "tOrderLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String T_ORDER = "tOrder";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_ORDER = "subOrder";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_ORDER_LATIN = "subOrderLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_SPECIES = "subSpecies";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_GENUS_LATIN = "subGenusLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_FAMILY_LATIN = "subFamilyLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_PHYLUMN = "subPhylumn";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String KINGDOM_LATIN = "kingdomLatin";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String SUB_KINGDOM_LATIN = "subKingdomLatin";

    /**
     * TODO Auto-generated method documentation
     *
     * @param organism
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<Taxonomy> findByOrganism(Organism organism, GlobalSearch globalSearch, Pageable pageable) {
        QTaxonomy taxonomy = QTaxonomy.taxonomy;
        JPQLQuery<Taxonomy> query = from(taxonomy);
        Assert.notNull(organism, "organism is required");
        query.where(taxonomy.organism.eq(organism));
        Path<?>[] paths = new Path<?>[] { taxonomy.organism, taxonomy.kingdom, taxonomy.kingdomLatin, taxonomy.subKingdom, taxonomy.subKingdomLatin, taxonomy.phylumn, taxonomy.phylumnLatin, taxonomy.subPhylumn, taxonomy.subPhylumnLatin, taxonomy.tClass, taxonomy.tClassLatin, taxonomy.subClass, taxonomy.subClassLatin, taxonomy.tOrder, taxonomy.tOrderLatin, taxonomy.subOrder, taxonomy.subOrderLatin, taxonomy.family, taxonomy.familyLatin, taxonomy.subFamily, taxonomy.subFamilyLatin, taxonomy.genus, taxonomy.genusLatin, taxonomy.subGenus, taxonomy.subGenusLatin, taxonomy.species, taxonomy.speciesLatin, taxonomy.subSpecies, taxonomy.subSpeciesLatin };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ORGANISM, taxonomy.organism).map(KINGDOM, taxonomy.kingdom).map(KINGDOM_LATIN, taxonomy.kingdomLatin).map(SUB_KINGDOM, taxonomy.subKingdom).map(SUB_KINGDOM_LATIN, taxonomy.subKingdomLatin).map(PHYLUMN, taxonomy.phylumn).map(PHYLUMN_LATIN, taxonomy.phylumnLatin).map(SUB_PHYLUMN, taxonomy.subPhylumn).map(SUB_PHYLUMN_LATIN, taxonomy.subPhylumnLatin).map(T_CLASS, taxonomy.tClass).map(T_CLASS_LATIN, taxonomy.tClassLatin).map(SUB_CLASS, taxonomy.subClass).map(SUB_CLASS_LATIN, taxonomy.subClassLatin).map(T_ORDER, taxonomy.tOrder).map(T_ORDER_LATIN, taxonomy.tOrderLatin).map(SUB_ORDER, taxonomy.subOrder).map(SUB_ORDER_LATIN, taxonomy.subOrderLatin).map(FAMILY, taxonomy.family).map(FAMILY_LATIN, taxonomy.familyLatin).map(SUB_FAMILY, taxonomy.subFamily).map(SUB_FAMILY_LATIN, taxonomy.subFamilyLatin).map(GENUS, taxonomy.genus).map(GENUS_LATIN, taxonomy.genusLatin).map(SUB_GENUS, taxonomy.subGenus).map(SUB_GENUS_LATIN, taxonomy.subGenusLatin).map(SPECIES, taxonomy.species).map(SPECIES_LATIN, taxonomy.speciesLatin).map(SUB_SPECIES, taxonomy.subSpecies).map(SUB_SPECIES_LATIN, taxonomy.subSpeciesLatin);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, taxonomy);
    }
}
